
					
					
					
		
										
Uec3.areaModule = Ext.extend(Ext.app.Module, {
    id: 'areaModule',
    objsCollection:new Ext.util.MixedCollection(true),
	getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
	initAll:function(params){
	
		this.test();
		return this.getObjByKey("partnerAddress_grid");
	},
	test:function(){
		var provinceId;
		var cityId=-1;
		var partnerAdress_storeProvince = new Ext.data.Store({
						proxy : new Ext.data.HttpProxy({
									url : Uec3.App.Constants.homeUrl
											+ '/area/toSelect.do'
								}),
						reader : new Ext.data.JsonReader({
									root : 'areas'
								}, [{
											name : 'id'
										}, {
											name : 'province'
										}])
					});

			var partnerAdress_storeCity = new Ext.data.Store({
						proxy : new Ext.data.HttpProxy({
									url : Uec3.App.Constants.homeUrl
											+ '/area/toSelect.do'
								}),
						reader : new Ext.data.JsonReader({
									root : 'areas'
								}, [{
											name : 'id'
										}, {
											name : 'city'
										}]),
				listeners:{
					'beforeload':function(){
						
					}
			}
			});

			var partnerAdress_storeCounty = new Ext.data.Store({
						proxy : new Ext.data.HttpProxy({
									url : Uec3.App.Constants.homeUrl
											+ '/area/toSelect.do'
								}),
						reader : new Ext.data.JsonReader({
									root : 'areas'
								}, [{
											name : 'id'
										}, {
											name : 'district'
										}])
					});
		// 初始化combox对象
		var	comboProvince = new Ext.form.ComboBox({
			name : 'province',
			store : partnerAdress_storeProvince,
			fieldLabel : '省份',
			emptyText : '--请选择--',
			mode : 'remote',
			triggerAction : 'all',
			valueField : 'province',
			displayField : 'province',
			forceSelection : true,
			selectOnFocus : true,
			typeAhead : true,
			loadingText : '加载中...',
			editable : false

	  });
      this.objsCollection.add('comboProvince',comboProvince);

		var	comboCity = new Ext.form.ComboBox({
			name : 'city',
			store : partnerAdress_storeCity,
			fieldLabel : '城市',
			emptyText : '--请选择--',
			mode : 'remote',
			typeAhead:true,
			typeAheadDelay:1000,
			triggerAction : 'all',
			forceSelection : true,
			valueField : 'city',
			displayField : 'city',
			loadingText : '加载中...',
			editable : false,
			listeners:{
				'beforequery':function(){
					alert(11);
				}
			}
		});
		this.objsCollection.add('comboCity',comboCity);
		var	comboCounty = new Ext.form.ComboBox({
			name : 'district',
			fieldLabel : '地区',
			store : partnerAdress_storeCounty,
			emptyText : '--请选择--',
			mode : 'remote',
			triggerAction : 'all',
			forceSelection : true,
			valueField : 'district',
			displayField : 'district',
			loadingText : '加载中...',
			editable : false
		});
		this.objsCollection.add('comboCounty',comboCounty);
		
				var partnerAdress_record = Ext.data.Record.create([{
						name : 'desc',
						type : 'string',
						mapping : 'desc'
					},

					{
						name : 'id',
						type : 'string',
						mapping : 'id'
					}, {
						name : 'partnerId',
						type : 'string',
						mapping : 'partnerId'
					},

					{
						name : 'areaId',
						type : 'string',
						mapping : 'areaId'
					}, {
						name : 'province',
						type : 'string',
						mapping : 'province'
					}, {
						name : 'city',
						type : 'string',
						mapping : 'city'
					}, {
						name : 'provinceId'
					}, {
						name : 'cityId'
					}, {
						name : 'district',
						type : 'string',
						mapping : 'district'
					}, {
						name : 'street',
						type : 'string',
						mapping : 'street'
					}, {
						name : 'postCode',
						type : 'string',
						mapping : 'postCode'
					}, {
						name : 'receiverName',
						type : 'string',
						mapping : 'receiverName'
					}, {
						name : 'phone',
						type : 'string',
						mapping : 'phone'
					}, {
						name : 'mobile',
						type : 'string',
						mapping : 'mobile'
					}]);

				
					
					
				var partnerAddress_ds = new Ext.data.Store({

				proxy : new Ext.data.HttpProxy({
							url : Uec3.App.Constants.homeUrl
									+ '/partnerAddress/query_partnerAddress!query.do'
						}),

				pruneModifiedRecords : true,
				reader : new Ext.data.JsonReader({
							root : 'root'
						}, partnerAdress_record

				),
				// 默认排序字段
				sortInfo : {
					field : "receiverName",
					direction : "asc"
				}

			});
			
		var render_partnerAddressDesc = function(value, cellmeta, record,
				rowIndex, columnIndex, store) {
			var str = "<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\"partner\").deletePartnerAddress("
					+ rowIndex + ");'>删除</a>";

			return str;

		}
			
			// 列模型对象
			var partnerAddress_colModel = new Ext.grid.ColumnModel([
					new Ext.grid.RowNumberer(),

					{
						header : "操作",
						width : 80,
						dataIndex : 'desc',
						renderer : render_partnerAddressDesc
					}, {
						header : "ID",
						hidden : true,
						width : 60,
						sortable : true,
						dataIndex : 'id'
					}, {
						header : "partnerId",
						hidden : true,
						width : 60,
						sortable : true,
						dataIndex : 'partnerId'
					}, {
						header : "地区",
						hidden : true,
						width : 80,
						sortable : true,
						dataIndex : 'areaId'
					}, {
						header : "省份",
						width : 80,
						sortable : true,
						dataIndex : 'province',
						editor : comboProvince
					}, {
						id : 'city',
						header : "城市",
						width : 80,
						sortable : true,
						dataIndex : 'city',
						editor : comboCity
					}, {
						header : "省ID",
						width : 60,
						sortable : true,
						dataIndex : 'provinceId',
						hidden : true
					}, {
						header : "市ID",
						width : 60,
						sortable : true,
						dataIndex : 'cityId',
						hidden : true
					}, {
						id : 'district',
						header : "区域",
						width : 80,
						sortable : true,
						dataIndex : 'district',
						editor : comboCounty,
						renderer : Ext.util.Format
								.comboRenderer(comboProvince)
					},
					{
						header : "详细地址",
						width : 80,
						sortable : true,
						dataIndex : 'street',
						editor : new Ext.grid.GridEditor(new Ext.form.TextField(
								{
								// allowBlank:false
								}))
					}, {
						header : "邮编",
						width : 80,
						sortable : true,
						dataIndex : 'postCode',
						editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
					}, {
						header : "收货人姓名",
						width : 100,
						sortable : true,
						dataIndex : 'receiverName',
						editor : new Ext.grid.GridEditor(new Ext.form.TextField(
								{
								// allowBlank:false
								}))
					}, {
						header : "电话",
						width : 80,
						sortable : true,
						dataIndex : 'phone',
						editor : new Ext.grid.GridEditor(new Ext.form.TextField(
								{
								// allowBlank:false
								}))
					}, {
						header : "手机",
						width : 60,
						sortable : true,
						dataIndex : 'mobile',
						editor : new Ext.grid.GridEditor(new Ext.form.TextField(
								{
								// allowBlank:false
								}))
					}
			]);
			
			
				// 初始化 partnerAddress表格对象
				var partnerAddress_grid = new Ext.grid.EditorGridPanel({
						disableSelection : true,
						id : 'partnerAddressGrid',
						store : partnerAddress_ds,
						height : 310,
						cm : partnerAddress_colModel,
						viewConfig : {
							forceFit : true,
							columnsText : '显示的列',
							scrollOffset : 30,
							sortAscText : '升序',
							sortDescText : '降序'
						},
						selModel : new Ext.grid.RowSelectionModel({
									moveEditorOnEnter : true,
									singleSelect : true
								}),
						iconCls : 'icon-grid',
						loadMask : {
							msg : '数据加载中...'
						},
						stripeRows : true,
						autoScroll : true,
						// plugins: checkColumn,
						clicksToEdit : 1,
						title : '客户收货地址',
						tbar : new Ext.Toolbar(['-', {
							text : '新增一行',
							icon : Uec3.App.Constants.deskUrl
									+ "/resources/images/default/dd/drop-add.gif",
							handler : function() {
								var p = new partnerAdress_record({
											desc : '',
											province : '',
											city : '',
											district : '',
											street : '',
											postCode : '',
											receiverName : '',
											phone : '',
											mobile : ''
										});
								partnerAddress_grid.stopEditing();
								// partnerAddress_ds.insert(0,p);
								partnerAddress_ds.addSorted(p);
								// partnerAddress_grid.getView().refresh();
								partnerAddress_grid.startEditing(0, 0);

							}
						}, '-']),
						listeners:{
							'cellclick':function(grid,rowIndex,columnIndex,e){
								if(columnIndex==5){
									
								}else if(columnIndex==6){
									var provinceValue=grid.getStore().getAt(rowIndex).get(comboProvince.displayField);
									var cCell=partnerAddress_colModel.getCellEditor(columnIndex,rowIndex);
									var index=comboProvince.getStore().findExact(comboProvince.displayField,provinceValue);
									cCell.setValue("");
									var pRecord=comboProvince.getStore().getAt(index);
									if(provinceId!=pRecord.get("id")){
										provinceId=pRecord.get("id");
										comboCity.getStore().baseParams.prov = provinceId;
										comboCity.getStore().load({
											callback:function(){
												cCell.setValue(comboCity.getStore().getAt(0).get(comboCity.displayField));
											}
										});
									}
								}else if(columnIndex==9){
									var cityValue=grid.getStore().getAt(rowIndex).get(comboCity.displayField);
									var aCell=partnerAddress_colModel.getCellEditor(columnIndex,rowIndex);
									aCell.setValue("");
									var index=comboCity.getStore().findExact(comboCity.displayField,cityValue);
									if(index==-1){
										var cityId=grid.getStore().getAt(rowIndex).get("cityId");
										comboCounty.getStore().baseParams.city = cityId;
										comboCounty.getStore().load({
											callback:function(){
												var record=comboCity.getStore().getAt(1);
												if(record){
													aCell.setValue(record.get('district'));
												}
											}
										});
										return;
									}else {
									var pRecord=comboCity.getStore().getAt(index);
										if(cityId!=pRecord.get("id")){
											cityId=pRecord.get("id");
											comboCounty.getStore().baseParams.city = cityId;
											comboCounty.getStore().load({
												callback:function(){
													var record=comboCounty.getStore().getAt(1);
													if(record){
														aCell.setValue(record.get('district'));
													}
												}
											});
										}
									}
								}
							},
							'afteredit':function(o){
								//var cell=partnerAddress_colModel.getCellEditor(o.column,o.row);
								if(o.column==5){
									var index=comboProvince.getStore().findExact(comboProvince.displayField,o.value);
									var pRecord=comboProvince.getStore().getAt(index);
									o.record.set('provinceId',pRecord.id);
									//cell.setValue(o.record.get(comboProvince.displayField));
								}else if(o.column==6){
									var index=comboCity.getStore().findExact(comboCity.displayField,o.value);
									var pRecord=comboCity.getStore().getAt(index);
									o.record.set('cityId',pRecord.id);
								}else if(o.column==9){
									var index=comboCounty.getStore().findExact(comboCounty.displayField,o.value);
									var pRecord=comboCounty.getStore().getAt(index);
									o.record.set('areaId',pRecord.id);
								}
								 
							}
							
						}

					});
				this.objsCollection.add('partnerAddress_grid',partnerAddress_grid);	
				Ext.util.Observable.capture(partnerAddress_grid,function(e){
				});
				
	},
    createWindow : function(params){
   	    var windowId=this.id;
   	    if(params){
   	  	    windowId+=Ext.isEmpty(params.winId)?"":"_"+params.winId;
   	    }
        var desktop = Uec3.App.getDesktop(); 
        var module=this;
        var win = desktop.getWindowByUecId(windowId);
        if(!win){
            win = desktop.createWindow({
            uecId: windowId,
            title: '3级地址测试',
            width: 1000,
            height: 500,
            iconCls: 'acc-icon',
            shim: false,
            animCollapse: false,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[module.initAll()],
            listeners:{
            }
            });
            this.objsCollection.add("win",win);
           // this.initFuns(params);
        } 
        win.show();
   }
});


